package ar.com.angrymachine.hunter.activities;

import java.awt.Graphics;
import java.awt.Rectangle;

import ar.com.angrymachine.hunter.Activity;
import ar.com.angrymachine.hunter.Game;
import ar.com.angrymachine.hunter.GraphicStyles;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.gameplay.Monster;

public class SlumberActivity extends Activity
{
	private static final int STATE_SLUMBERING = 0;
	private static final int STATE_WAKEN = 1;
	private int state = STATE_SLUMBERING;
	Monster monster;
	private int wakeTime;
	private int currentWakeTime = 0;

	
	public SlumberActivity(Monster monster, int wakeTime)
	{
		this.monster = monster;
		this.wakeTime = wakeTime;
	}
	
    public void paint(Graphics g, Rectangle activityArea)
    {
        GraphicStyles.paintDefaultActivity(g, this, activityArea, monster.icon);
        if(!isCompleted())
        {
        	Rectangle bar = GraphicStyles.getBarArea(activityArea);
            g.setColor(GraphicStyles.slumberBarColor());
            GraphicStyles.paintLabeledBar(g, Locale.WAKING, bar, currentWakeTime, wakeTime);
        }
    }
	
    public void update(int delta, boolean action, boolean timeIsRunning)
    {
        if(timeIsRunning)
        {
            if(action)
            {
            	if(state == STATE_SLUMBERING)
            	{
            		//state = STATE_WAKEN;
            	}
            }
            currentWakeTime += delta;
            if(currentWakeTime >= wakeTime)
            {
            	state = STATE_WAKEN;
            }
        }
    }
    
    public void onFinished()
    {
        Game.current.currentLevel.addActivity(this, new FightActivity(monster));
    }

	public String getDescription()
	{
		return Locale.getSlumberingMonsterLabel(monster);
	}

	public String getActionText()
	{
		return Locale.WAKE;
	}

	public boolean isCompleted()
	{
		return state == STATE_WAKEN;
	}

}
